<script>
  highlight_subnav('goodslist');
</script>

 <!-- 内容区域 -->
  <div class="row">

                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">边框表单</div>
                                <div class="widget-function am-fr">
                                    <a href="javascript:;" class="am-icon-cog"></a>
                                </div>
                            </div>
                            <div class="widget-body am-fr">

                                <form action="editGoods" method="post" class="am-form tpl-form-border-form tpl-form-border-br" enctype="multipart/form-data" onsubmit="checkForm()">
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">商品名 <span class="tpl-form-line-small-title">name</span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="tpl-form-input"  name="name" id='goodsname' maxlength='18' value="<?php echo $info['name'];?>" placeholder="请输入商品名">
                                            <small>请填写标题文字1-18字左右。</small>
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">商品副标题 <span class="tpl-form-line-small-title">subhead</span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="tpl-form-input" id="other_name" maxlength='30' name="other_name"  value="<?php echo $info['other_name'];?>" placeholder="请输入商品副标题">
                                            <small>请填写标题文字1-30字左右。</small>
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">价格 <span class="tpl-form-line-small-title">price</span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="tpl-form-input" id="price" name="price"  value="<?php echo $info['price'];?>" placeholder="请输入商品价格">
                                            
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">商品描述 <span class="tpl-form-line-small-title">descript</span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="tpl-form-input" id="descript" name="descript" maxlength='10' value="<?php echo $info['descript'];?>" placeholder="请输入活动描述">
                                            <small>请填写标题文字1-10字左右。</small>
                                        </div>
                                    </div>
                                    
                                    <div class="am-form-group">
                                        <label for="user-phone" class="am-u-sm-3 am-form-label">活动类型 <span class="tpl-form-line-small-title">class</span></label>
                                        <div class="am-u-sm-9">
                                            <select data-am-selected="{searchBox: 1}" style="display: none;" name="activity_id" id="activity_id">
                                              <option value="0">--请选择活动类型--</option>
                                              <?php foreach($info['activity'] as $key => $value){?>
                                              <option value="<?php echo $value['activity_id']?>" <?php if($info['activity_id'] == $value['activity_id']){echo "selected";}?>><?php echo $value['activity_name']?></option>
                                              <?php }?>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <label for="user-weibo" class="am-u-sm-3 am-form-label">商品banner图 <span class="tpl-form-line-small-title">Images</span></label>
                                        <div class="am-u-sm-9">
                                            <div class="am-form-group am-form-file" style="width:135px">
                                                <div class="tpl-form-file-img img1">
                                                    <img src="<?php if(!empty($info['banner_img'])){echo $base_path.$info['banner_img']['img_path'][0];}?>" alt="<?php if(!empty($info['banner_img'])){echo $info['banner_img']['img_name'][0];}?>" <?php if(!empty($info['banner_img'])){?>style="height:100px;width:100px;"<?php }?>>
                                                </div>
                                                <button type="button" class="am-btn am-btn-danger am-btn-sm">
                                                    <i class="am-icon-cloud-upload"></i> 添加商品图片</button>
                                                <input name="img[]" id="doc-form-file1" type="file"  class="file1">
                                            </div>

											<div class="img-box">																								
											</div>
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="user-weibo" class="am-u-sm-3 am-form-label">商品轮播图 <span class="tpl-form-line-small-title">Images</span></label>
                                        <div class="am-u-sm-9">
                                            <div class="am-form-group am-form-file" style="width:135px">
                                                <div class="tpl-form-file-img img2">
                                                <?php
                                                    $ads = $info['ads_img'];          
                                                    if(!empty($ads)){
                                                    foreach ($ads['img_path'] as $key => $value){     
                                                ?>
                                                    <img src="<?php echo $base_path.$value;?>" alt="<?php echo $ads['img_name'][$key];?>" style="height:100px;width:100px;">
                                                <?php }}?>
                                                </div>
                                                <button type="button" class="am-btn am-btn-danger am-btn-sm">
                                                    <i class="am-icon-cloud-upload"></i> 添加商品图片</button>
                                                <input name="img[]" id="doc-form-file2" type="file" multiple="multiple" class="file2">
                                            </div>

											<div class="img-box">																								
											</div>
                                        </div>
                                    </div>
                                   

                                    <div class="am-form-group">
                                        <label for="user-intro" class="am-u-sm-3 am-form-label">是否上线</label>
                                        <div class="am-u-sm-9">
                                            <div class="tpl-switch">
                                                <input type="checkbox" name="status" class="ios-switch bigswitch tpl-switch-btn" <?php if($info['status']=='on'){echo "checked";}?>>
                                                <div class="tpl-switch-btn-view">
                                                    <div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <label for="user-intro" class="am-u-sm-3 am-form-label">商品详情</label>
                                        <div class="am-u-sm-9">
                                            <textarea class="" rows="10" id="editor1" placeholder="请输入文章内容" name="goods_detail" style="height:400px;"><?php echo $info['goods_detail'];?></textarea>
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="user-intro" class="am-u-sm-3 am-form-label">商品参数</label>
                                        <div class="am-u-sm-9">
                                            <textarea class="" rows="10" id="editor2" placeholder="请输入文章内容" name="goods_params" style="height:400px;"><?php echo $info['goods_params'];?></textarea>
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <div class="am-u-sm-9 am-u-sm-push-3">
                                            <input type="submit" class="am-btn am-btn-primary tpl-btn-bg-color-success " id='submit' value="提交"/>
                                            <a onclick='history.go(-1)' class="am-btn am-btn-primary tpl-btn-bg-color-success ">返回</a>
                                        </div>
                                    </div>
                                    <input type="hidden" name="goods_id" value="<?php echo $info['goods_id']?>">
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                <script charset="utf-8" src="/static/js/kindeditor/kindeditor.js"></script>
                <!--<script charset="utf-8" src="/static/js/kindeditor/lang/zh-CN.js"></script>-->
                <script>
                    KindEditor.ready(function(K) {
                            window.editor1 = K.create('#editor1');
                            window.editor2 = K.create('#editor2');
                       
                    });

					// $(".file1").on('change',function(e){												
					// 	var file=this;						
					// 	var src= "", el = $(this).parents(".am-u-sm-9").find(".img-box");
						
					// 	 if (file.files && file.files[0]){
					// 		var reader = new FileReader();							
					// 		reader.readAsDataURL(file.files[0]);
					// 		reader.onload = function(evt){
					// 			src = evt.target.result;								
					// 			el.html(crateImg(src));
					// 		}
					// 	 }						
					// })

                    $(function(){
                        var mysubmit = document.getElementById('submit');
                        mysubmit.onclick=function(event){
                            var price = $('#price').val(); 
                            var goodname  = $('#goodsname').val();
                            var file1 = $('#doc-form-file1').val();
                            var file2 = $('#doc-form-file2').val();
                            var activity = $('#activity_id').val();
                            var other_name = $('#other_name').val();
                            var img1 = $('.img1').find('img').attr('src');
                            var img2 = $('.img2').find('img').attr('src')
                            if(!goodname){
                                alert("商品名不能为空！");
                                return false; 
                            }
                            if(price=='0' || price=='0.0' || price=='0.00')
                            {
                                alert("商品价格不能为0");
                                return false; 
                            }
                            var reg = /(^[-+]?[1-9]\d*(\.\d{1,2})?$)|(^[-+]?[0]{1}(\.\d{1,2})?$)/;
                            if (price == "") {
                                alert("商品价格不能为空！");
                                return false; 
                            } else {
                                if (!reg.test(price)) {
                                    alert("市场价格必须为合法数字(正数，最多两位小数)！");
                                    return false; 
                                } 
                            }
                            if(!other_name){
                                alert("商品副标题不能为空");
                                return false;
                            }
                            if(activity == 0){
                                alert("活动类型不能为空");
                                return false;  
                            }
                            if(!file1 && !img1){
                                alert("商品banner图不能为空");
                                return false;   
                            }
                            if(!file2 && !img2){
                                alert("商品轮播图不能为空");
                                return false;  
                            }
                            if(!editor1.html()){
                                alert("商品详情不能为空");
                                return false;   
                            }
                            if(!editor2.html()){
                                alert("商品参数不能为空");
                                return false;  
                            }
                            
                        }
                    })
                        
                   

					$(".file2,.file1").on('change',function(e){	
						var file=this;						
						var el = $(this).parents(".am-u-sm-9").find(".img-box");						
						el.html("");
						if(this.files.length>3){
							el.html('<span class="am-badge am-badge-danger"> 不能超过3张 </span>')
						}else{
							for(var i = 0; i< this.files.length;i++){
							if (file.files && file.files[i]){
								var reader = new FileReader();							
								reader.readAsDataURL(file.files[i]);
								reader.onload = function(evt){													
									el.append(crateImg(evt.target.result));
									}
								}			
							}	
						}
											
								
					})

					function crateImg(src){						
						return $('<img>').attr('src',src);
					}


					function getQueryString(name) { 
						var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
						var r = window.location.search.substr(1).match(reg); 
						if (r != null) return unescape(r[2]); return null; 
					} 

					
					var goods_id = getQueryString('goods_id')

					if(goods_id){
						$('#price').attr('readonly','readonly');
						$('#price').attr('disabled','disabled');
						$('#price').css({'border':'#838FA1','color':'#838FA1'})
						$('#activity_id').attr('readonly','readonly');
						$('#activity_id').attr('disabled','disabled');
						
					}

                </script>

</body>

</html>


       
